import { Renderer, parse } from 'marked'
// 进行解析marked文档以及 就行代码高亮
// import Prism from 'prismjs'
import 'prismjs/themes/prism-coy.min.css'
import hljs from 'highlight.js'
import 'highlight.js/styles/github.css'

const renderer = {
  code (code, infostring, escaped) {
    const highlightCode = hljs.highlightAuto(code)
    return `<pre><code>${highlightCode.value}</code></pre>`

    // console.log({ code, infostring, escaped }, Prism.languages)
    // 容错处理  没有值得情况下
    // const isFind = (Prism.languages[infostring])
    // infostring有值  并且 isFind 也有值
    // const md = isFind ? Prism.highlight(code, Prism.languages[infostring], infostring) : code
    // console.log({ md })
    // return `<pre class="language-${infostring}"><code class="language-${infostring}">${code}</code></pre>`
    // return `<div v-highlight><pre><code>${code}</code></pre> </div>`
  }
}

export const useMarked = (value) => {
  const htmlStr = parse(value, {
    renderer: Object.assign(new Renderer(), renderer)
  })
  return htmlStr
}
